package com.dominator.shiro;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;

/**
 * @author gsh
 * @since 0.0.1
 */
public class DBRealmPzb extends AuthorizingRealm {

	@Override
	protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken arg0) throws AuthenticationException {
		// TODO Auto-generated method stub
		return null;
	}
//	@Autowired
//	AdminService adminService;
//	@Autowired
//	ModuleService mdService;
//	@Autowired
//	RoleService roleService;
//
//	@Override
//	protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principal) {
//		AdminPrincipal user = (AdminPrincipal) principal.getPrimaryPrincipal();
//		Session session = SecurityUtils.getSubject().getSession();
//		SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
//
//		List<Role> rolelist = roleService.getAdminRoles(user.getId());
//		StringBuilder sb = new StringBuilder();
//		for (Role role : rolelist) {
//			info.addRole(role.getId().toString());
//			sb.append(role.getName() + ",");
//		}
//		String str = sb.toString();
//		if (!StringUtils.isEmpty(str) && str.endsWith(","))
//			str = str.substring(0, str.length() - 1);
//		session.setAttribute("roles", str);
//
//		List<Module> mdlist = mdService.getAdminModule(user.getId());
//		for (Module module : mdlist) {
//			info.addStringPermission(module.getId().toString());
//		}
//
//		return info;
//
//	}
//
//	@Override
//	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
//			throws AuthenticationException {
//		UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
//		if (StringUtils.isEmpty(token.getUsername())) {
//			throw new AccountException("The Username are not allowed.");
//		}
//
//		String password = new String((char[]) token.getCredentials());
//		Admin dbUser = adminService.getLoginAdmin(token.getUsername(), password);
//		if (dbUser == null) {
//			throw new AuthenticationException("USER_NOT_EXISTS");
//
//		} else if (dbUser.getIsEnable() != 1) {
//			throw new AuthenticationException("USER_DISABLED");
//		}
//
//		BeanCopier copy = BeanCopier.create(Admin.class, AdminPrincipal.class, false);
//		AdminPrincipal user = new AdminPrincipal();
//		copy.copy(dbUser, user, null);
//
//		token.setPassword(user.getPassword().toCharArray());
//		SimpleAuthenticationInfo authenticationInfo = null;
//		if (user != null) {
//			authenticationInfo = new SimpleAuthenticationInfo(user, user.getPassword(), this.getName());
//		}
//
//		return authenticationInfo;
//	}

}
